package com.gpnu.crm.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;
import com.gpnu.crm.domain.Department;
import com.gpnu.crm.query.QueryObject;
import com.gpnu.crm.service.IDepartmentService;
import com.gpnu.crm.util.JSONResult;

@Controller
@RequestMapping("/department")
public class DepartmentController {
	@Autowired
	private IDepartmentService departmentService;

	@RequestMapping("/list")
	public String list(@ModelAttribute("qo")QueryObject qo, Model model) {
		PageInfo<Department> info = departmentService.query(qo);
		model.addAttribute("pageInfo", info);
		return "department/list";
	}

	@RequestMapping("/saveOrUpdate")
	public String saveOrUpdate(Department entity) {
		departmentService.saveOrUpdate(entity);
		return "redirect:/department/list.do";
	}

	@RequestMapping("/delete")
	public String delete(Long id) {
		departmentService.delete(id);
		return "redirect:/department/list.do";
	}
}
